package com.ruoyi.car.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.car.domain.CarMaintenanceRecord;
import com.ruoyi.car.service.ICarMaintenanceRecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 维修保养记录Controller
 * 
 * @author ruoyi
 * @date 2022-12-03
 */
@RestController
@RequestMapping("/car/record")
public class CarMaintenanceRecordController extends BaseController
{
    @Autowired
    private ICarMaintenanceRecordService carMaintenanceRecordService;

    /**
     * 查询维修保养记录列表
     */
    @PreAuthorize("@ss.hasPermi('car:record:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarMaintenanceRecord carMaintenanceRecord)
    {
        startPage();
        List<CarMaintenanceRecord> list = carMaintenanceRecordService.selectCarMaintenanceRecordList(carMaintenanceRecord);
        return getDataTable(list);
    }

    /**
     * 导出维修保养记录列表
     */
    @PreAuthorize("@ss.hasPermi('car:record:export')")
    @Log(title = "维修保养记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarMaintenanceRecord carMaintenanceRecord)
    {
        List<CarMaintenanceRecord> list = carMaintenanceRecordService.selectCarMaintenanceRecordList(carMaintenanceRecord);
        ExcelUtil<CarMaintenanceRecord> util = new ExcelUtil<CarMaintenanceRecord>(CarMaintenanceRecord.class);
        util.exportExcel(response, list, "维修保养记录数据");
    }

    /**
     * 获取维修保养记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('car:record:query')")
    @GetMapping(value = "/{maintenanceRecordId}")
    public AjaxResult getInfo(@PathVariable("maintenanceRecordId") Long maintenanceRecordId)
    {
        return success(carMaintenanceRecordService.selectCarMaintenanceRecordByMaintenanceRecordId(maintenanceRecordId));
    }

    /**
     * 新增维修保养记录
     */
    @PreAuthorize("@ss.hasPermi('car:record:add')")
    @Log(title = "维修保养记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarMaintenanceRecord carMaintenanceRecord)
    {
        return toAjax(carMaintenanceRecordService.insertCarMaintenanceRecord(carMaintenanceRecord));
    }

    /**
     * 修改维修保养记录
     */
    @PreAuthorize("@ss.hasPermi('car:record:edit')")
    @Log(title = "维修保养记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarMaintenanceRecord carMaintenanceRecord)
    {
        return toAjax(carMaintenanceRecordService.updateCarMaintenanceRecord(carMaintenanceRecord));
    }

    /**
     * 删除维修保养记录
     */
    @PreAuthorize("@ss.hasPermi('car:record:remove')")
    @Log(title = "维修保养记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{maintenanceRecordIds}")
    public AjaxResult remove(@PathVariable Long[] maintenanceRecordIds)
    {
        return toAjax(carMaintenanceRecordService.deleteCarMaintenanceRecordByMaintenanceRecordIds(maintenanceRecordIds));
    }
}
